<admintpl file="header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('News/index')}">项目动态</a></li>
			<li class="active"><a href="{:U('News/add')}">添加动态</a></li>
		</ul>
        <form method="post" class="form-horizontal" action="{:U('News/add_post')}">


            <fieldset>
                <div class="form-group">
                    <label class="col-md-2 control-label">
                        标题<span class="required" aria-required="true"> * </span>
                    </label>
                    <div class="col-md-6">
                        <input type="hidden" name="type" value="1">
                        <input type="text" name="title" class="form-control" required >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">选择图片</label>
                    <div class="col-md-6">
                        <a class="btn upBtn btn-primary" href="javascript:void(0);">上传</a>
                        <input type="file" id="upFile" name="upFile" accept="image/gif, image/x-ms-bmp, image/jpeg, image/png" style="display:none" />
                        <input type="hidden" name="thumbnail" id="imageUrl" />
                        <img id="showImage" src="" style="display:none" width="50">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">内容</label>
                    <div class="col-md-8">
                        <script type="text/plain" id="content" name="content">
                        </script>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">
                        来源
                    </label>
                    <div class="col-md-6">
                        <input type="text" name="source"  class="form-control">
                    </div>
                </div>
                <!--<div class="form-group">
                    <label class="col-md-2 control-label">作者</label>
                    <div class="col-md-6">
                        <input type="text" name="author">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">发布时间</label>
                    <div class="col-md-6">
                        <input type="text" class="js-date" name="publish_time">
                    </div>
                </div>-->
            </fieldset>
            <div class="form-actions col-md-10 col-md-offset-2">
                <button type="submit" class="btn btn-primary js-ajax-submit">{:L('ADD')}</button>
                <a class="btn btn-default" href="javascript:history.back(-1);">{:L('BACK')}</a>
            </div>
        </form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.WEB_ROOT;
	</script>
    
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript">
		var editorcontent = new baidu.editor.ui.Editor();
		editorcontent.render('content');
	</script>
    <script type="text/javascript">
		// 图片上传
        $(document).ready(function (e) {

            
            $("form input").addClass("form-control");

			// 选择图片
			$(document).on("click", ".upBtn", function(e) {
				$("#upFile").click();
			});
			// 文件选择器change事件
			$("#upFile").on("change", function(){
				fileUpload();
			});
			fileUpload = function(){
				if($("#upFile").val() == ""){
					alert("请选择待上传文件！");
					return false;
				}
				$.ajaxFileUpload({
					url : "{:U('News/uploadImg')}",
					secureuri : false, //安全协议
					fileElementId:'upFile', //id
					type : 'post',
					dataType : 'json',
					data:{
						'imageURL': $("#imageUrl").val(),
						'ajax': 1},
					async : false,
					error : function(data,status,e) {
						alert("服务器内部错误！");
					},
					success : function(json) {
						if (json.rtnType == 'T'){
							$("#imageUrl").val(json.rtnResult);
							$("#showImage").attr("src", "/"+json.rtnResult).show();
						} else {
							alert(json.rtnMsg);
						}
					},
					complete: function(xmlHttpRequest) {
						// 上传一次后 onchange事件失效，重新绘制上传文件文件框
						$("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" accept="image/gif, image/x-ms-bmp, image/jpeg, image/png" style="display:none" />');
						$("#upFile").on("change", function(){
							fileUpload();
						});
					}
				});
			}
		});
	</script>
</body>
</html>